home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Games Collection 1 / software vault.zip / software vault / CDR09 / JOYSDK11.ZIP / RDAXIS_S.LST < prev    next >
File List  |  1992-02-17  |  10KB  |  242 lines

  1. Microsoft (R) Macro Assembler Version 5.10                  2/17/92 16:13:56
  2.                                                              Page     1-1
  3.  
  4.  
  5.                         page    ,132
  6.                 ;------------------------------------------------------------------------------
  7.                 ; Module Name: READAXIS.ASM
  8.                 ;
  9.                 ; Assembly language routine for reading joystick axis position
  10.                 ;
  11.                 ; Created: Feb 17th, 1992
  12.                 ; Author: Peter Wan
  13.                 ;
  14.                 ; Copyright (c) 1992 Advanced Gravis Computer Technology Limited
  15.                 ;
  16.                 ; Public Functions:
  17.                 ;    get_loop_count
  18.                 ;    read_axis
  19.                 ; Public Data:
  20.                 ;    None
  21.                 ; General Description:
  22.                 ;    This module contains functions to initialize itself and return
  23.                 ;    joystick axis position.
  24.                 ;------------------------------------------------------------------------------
  25.                 
  26.                         dosseg
  27.                         .model     small
  28.                 
  29.                 ;------------------------------------------------------------------------------
  30.                 ; Port address
  31.                 ;------------------------------------------------------------------------------
  32.  = 0201                GAMEPORT    equ    201h        ;gameport address
  33.  = 0040                TIMER0        equ    40h        ;8253 counter timer channel 0 address
  34.  = 0043                TIMER_CONTROL    equ    43h        ;counter timer control register address
  35.                 
  36.                         .data
  37.  0000  0000            max_loop_count    dw    ?        ;loop count for 3 milliseconds
  38.                 
  39.                         .code
  40.                 
  41.                 ;------------------------------------------------------------------------------
  42.                 ; get_loop_count
  43.                 ;
  44.                 ; The purpose of this routine is to determine how many iteration of the
  45.                 ; following instruction loop can be accomplished in 3 milliseconds.  The number
  46.                 ; of iteration count will be different on computers running at different speed
  47.                 ; or computers with different processing unit.    In the read joystick axis
  48.                 ; routine, it uses a similar program loop to determine joystick axis position
  49.                 ; and the count results from this routine will be used to limit axis read time
  50.                 ; up to 3 millesecond maximum.    This routine must be called once at
  51.                 ; initialization time.
  52.                 ;
  53.                 ; Entry:
  54.                 ;    None
  55.                 ; Returns:
  56.                 ;    None
  57.                 ; Error Returns:
  58.                 ;    None
  59. Microsoft (R) Macro Assembler Version 5.10                  2/17/92 16:13:56
  60.                                                              Page     1-2
  61.  
  62.  
  63.                 ; Registers Preserved:
  64.                 ;    BX,SI,DI,BP,DS,ES
  65.                 ; Registers Destroyed:
  66.                 ;    AX,CX,DX
  67.                 ; Calls:
  68.                 ;    None
  69.                 ;------------------------------------------------------------------------------
  70.                 
  71.                         public    _get_loop_count
  72.  0000                _get_loop_count proc
  73.  = [bp-2]            init_count    equ    <[bp-2]>
  74.  0000  55                    push    bp
  75.  0001  8B EC                    mov    bp,sp
  76.  0003  83 EC 02                    sub    sp,2        ;2 bytes of local variable
  77.  0006  C7 06 0000 R 0000            mov    max_loop_count,0;use loop count of 16 to start with
  78.  000C  BA 0201                    mov    dx,GAMEPORT    ;gameport address
  79.  000F                glc3:
  80.  000F  B8 FF00                    mov    ax,0ff00h
  81.  0012  83 06 0000 R 10                add    max_loop_count,16
  82.  0017  8B 0E 0000 R                mov    cx,max_loop_count
  83.  001B  FA                    cli            ;system interrupt must be disabled
  84.  001C  E6 43                    out    TIMER_CONTROL,al;latch count in timer 0
  85.  001E  EB 00                    jmp    short $+2
  86.  0020  E4 40                    in    al,TIMER0    ;read low byte of latched count
  87.  0022  88 46 FE                    mov    init_count,al    ;save
  88.  0025  EB 00                    jmp    short $+2
  89.  0027  E4 40                    in    al,TIMER0    ;read high byte
  90.  0029  88 46 FF                    mov    init_count+1,al ;save
  91.  002C  EE                    out    dx,al        ;trigger gameport
  92.  002D  EC                    in    al,dx        ;delay to allow gameport to switch on
  93.  002E                glc4:                    ;the following loop exits only when CX
  94.                                     ;reaches zero
  95.  002E  EC                    in    al,dx
  96.  002F  0A C4                    or    al,ah
  97.  0031  E0 FB                    loopnz    glc4
  98.  0033  B8 0000                    mov    ax,0
  99.  0036  75 00                    jnz    $+2
  100.  0038  E6 43                    out    TIMER_CONTROL,al;latch count in timer 0
  101.  003A  FB                    sti            ;enable system interrupt
  102.  003B  EB 00                    jmp    short $+2
  103.  003D  E4 40                    in    al,TIMER0    ;read low byte of latched count
  104.  003F  8A E0                    mov    ah,al
  105.  0041  EB 00                    jmp    short $+2
  106.  0043  E4 40                    in    al,TIMER0    ;read high byte
  107.  0045  86 C4                    xchg    al,ah
  108.  0047  2B 46 FE                    sub    ax,init_count    ;subtract count latched before
  109.                                     ;entering loop by count just read
  110.  004A  F7 D8                    neg    ax
  111.  004C  3D 1BF8                    cmp    ax,7160     ;has it exceed 3 milliseconds?
  112.  004F  7C BE                    jl    glc3        ;no, increment loop count by 16 and
  113.                                     ;repeat process
  114.  0051  8B E5                    mov    sp,bp
  115.  0053  5D                    pop    bp
  116.  0054  C3                    ret
  117. Microsoft (R) Macro Assembler Version 5.10                  2/17/92 16:13:56
  118.                                                              Page     1-3
  119.  
  120.  
  121.  0055                _get_loop_count endp
  122.                 
  123.                 ;------------------------------------------------------------------------------
  124.                 ; _read_axis
  125.                 ;
  126.                 ; This routine will accept a number from 0 to 3 for returning joystick axis
  127.                 ; position for joystick A-X, A-Y, B-X, B-Y respectively.  After bit position
  128.                 ; of requested axis is determined, count reading in counter timer chip channel 0
  129.                 ; will be read and saved.  A write cycle to gameport address 201 hex will
  130.                 ; trigger and toggle all four axis lines from low to high state.  The duration
  131.                 ; of these individual line staying high is directly proportional to the
  132.                 ; position of joystick for the individual axis.  After the requested axis line
  133.                 ; has returned to the low state, count reading in counter timer chip will be
  134.                 ; read again. The real time count of the duration the requested axis has stayed
  135.                 ; high can be obtained from the difference of the two counts read.  Allowance
  136.                 ; for other axis to return to low state must also be provided before next read.
  137.                 ; Therefore, return to calling function can only be done at the end of the
  138.                 ; 3 milliseconds duration.  The real time count return to the callind function
  139.                 ; can have a value ranges from 1 to maximum of 7160 depending on the position
  140.                 ; of the joystick, value of capacitors used and threshold voltage set
  141.                 ; on the gamecard.  If the requested axis has not returned to the low state
  142.                 ; after 3 milliseconds, it is assumed that no joystick is connected to that
  143.                 ; axis and zero will be returned to the calling function.  During the
  144.                 ; 3 milliseconds duration, all interrupts except NMI will be disabled.
  145.                 ;
  146.                 ; Entry:
  147.                 ;    [bp+4] = Axis to be read
  148.                 ;         0 = Joystick A - X axis
  149.                 ;         1 = Joystick A - Y axis
  150.                 ;         2 = Joystick B - X axis
  151.                 ;         3 = Joystick B - Y axis
  152.                 ; Returns:
  153.                 ;    AX = Count ranges from 1 to maximun of 7160 corresponds to joystick
  154.                 ;         position
  155.                 ; Error Returns:
  156.                 ;    AX = 0 if no joystick connected
  157.                 ; Registers Preserved:
  158.                 ;    BX,SI,DI,BP,DS,ES
  159.                 ; Registers Destroyed:
  160.                 ;    AX,CX,DX
  161.                 ; Calls:
  162.                 ;    None
  163.                 ;------------------------------------------------------------------------------
  164.                 
  165.                         public    _read_axis
  166.  0055                _read_axis    proc
  167.  = [bp+4]            axis        equ    <[bp+4]>
  168.  = [bp-2]            init_count    equ    <[bp-2]>
  169.  0055  55                    push    bp
  170.  0056  8B EC                    mov    bp,sp
  171.  0058  83 EC 02                    sub    sp,2        ;2 bytes of local variable
  172.  005B  2B C0                    sub    ax,ax        ;determine bit position of axis to be
  173.  005D  B4 01                    mov    ah,1        ;read
  174.  005F  8B 4E 04                    mov    cx,axis
  175. Microsoft (R) Macro Assembler Version 5.10                  2/17/92 16:13:56
  176.                                                              Page     1-4
  177.  
  178.  
  179.  0062  D2 E4                    shl    ah,cl
  180.  0064  8B 0E 0000 R                mov    cx,max_loop_count;use 3 milliseconds loop count obtian
  181.                                     ;at initailization
  182.  0068  BA 0201                    mov    dx,GAMEPORT    ;gameport address
  183.  006B  FA                    cli            ;disable interrupt
  184.  006C  E6 43                    out    TIMER_CONTROL,al;latch count in timer 0
  185.  006E  EB 00                    jmp    short $+2
  186.  0070  E4 40                    in    al,TIMER0    ;read low byte of latched count
  187.  0072  88 46 FE                    mov    init_count,al    ;save
  188.  0075  EB 00                    jmp    short $+2
  189.  0077  E4 40                    in    al,TIMER0    ;read high byte
  190.  0079  88 46 FF                    mov    init_count+1,al ;save
  191.  007C  EE                    out    dx,al        ;trigger gameport
  192.  007D  EC                    in    al,dx        ;delay to allow gameport to switch on
  193.  007E                ra1:
  194.  007E  EC                    in    al,dx        ;read gameport
  195.  007F  84 C4                    test    al,ah        ;requested axis return to low state or
  196.                                     ;3 milliseconds passed?
  197.  0081  E0 FB                    loopnz    ra1        ;no
  198.  0083  B8 0000                    mov    ax,0        ;return 0 if 3 milliseconds passed and
  199.  0086  75 1E                    jnz    ra3        ;requested axis not yet in low state
  200.  0088  E6 43                    out    TIMER_CONTROL,al;requested axis return to low state
  201.                                     ;latch count in timer 0
  202.  008A  EB 00                    jmp    short $+2
  203.  008C  E4 40                    in    al,TIMER0    ;read low byte of latched count
  204.  008E  8A E0                    mov    ah,al
  205.  0090  EB 00                    jmp    short $+2
  206.  0092  E4 40                    in    al,TIMER0    ;read high byte
  207.  0094  86 C4                    xchg    al,ah
  208.  0096  2B 46 FE                    sub    ax,init_count    ;obtain real time count of high state
  209.  0099  F7 D8                    neg    ax        ;duration
  210.  009B  E3 09                    jcxz    ra3        ;requested axis return to low state in
  211.                                     ;exactly 3 milliseconds, all other axis
  212.                                     ;should also have returned to low state
  213.                                     ;by now
  214.  009D  50                    push    ax        ;even though the requested axis has
  215.  009E  B4 FF                    mov    ah,0ffh     ;returned to the low state, other axis
  216.  00A0                ra2:                    ;may still be in the high state, we
  217.  00A0  EC                    in    al,dx        ;should wait till the end of the
  218.  00A1  0A C4                    or    al,ah        ;3 milliseconds duration to allow the
  219.  00A3  E0 FB                    loopnz    ra2        ;other axis to return to high state
  220.  00A5  58                    pop    ax        ;before returning to the calling
  221.                                     ;fucntion
  222.  00A6                ra3:
  223.  00A6  FB                    sti            ;enable system interrupt
  224.  00A7  8B E5                    mov    sp,bp
  225.  00A9  5D                    pop    bp
  226.  00AA  C3                    ret
  227.  00AB                _read_axis    endp
  228.                         end
  229. Microsoft (R) Macro Assembler Version 5.10                  2/17/92 16:13:56
  230.                                                              Page     1-5
  231.  
  232.  
  233.  
  234.     212 Source  Lines
  235.     212 Total   Lines
  236.      33 Symbols
  237.  
  238.   47362 + 421160 Bytes symbol space free
  239.  
  240.       0 Warning Errors
  241.       0 Severe  Errors
  242.